/**
 * 页面初始化加载项
 */
$(document).ready(function () {
    LoginFormOp.init();
});

/**
 * 申报明细操作
 * @type {{init: LoginFormOp.init, form: null, queryData: {}, cxtjHide: LoginFormOp.cxtjHide, doQuery: LoginFormOp.doQuery, doReset: LoginFormOp.doReset, datagrid: null, onDrawCell: LoginFormOp.onDrawCell}}
 */
var LoginFormOp = {
    //表单对象
    form      : null,
    //数据
    saveData : {},
    //页面初始化
    init: function(){
        LoginFormOp.form = new mini.Form("LoginForm");
    },
    /**
     * 登录功能
     */
    doLogin: function(){
        //校验必填条件
        LoginFormOp.form.validate();
        if (!LoginFormOp.form.isValid()){
            return;
        }
        //获取表单条件
        LoginFormOp.saveData = LoginFormOp.form.getData(true);
        // alert(LoginFormOp.saveData.user_pass)
        //校验
        if (LoginFormOp.saveData.user_name == null || LoginFormOp.saveData.user_name == ""){
            mini.alert("用户名不能为空");
            return;
        }
        if (LoginFormOp.saveData.user_pass == null || LoginFormOp.saveData.user_pass == ""){
            mini.alert("密码不能为空");
            return;
        }
        //提交登录
        LoginFormOp.submit(LoginFormOp.saveData);
    },
    submit: function(data){
        var btn = mini.get("loginBtn");
        btn.disable()

        setTimeout(function () {
            jQuery.ajax({
                url: "/loginUser",
                type: "POST",
                async: true,
                dataType: "json",
                data: data,
                success: function(res) {
                    btn.enable()
                    if (res.code == 200){
                        mini.alert(res.msg);
                    } else {
                        mini.alert(res.msg);
                    }
                }
            });
        },2000)

    }
};
